<?php
switch ($_REQUEST['sAction'])
{
	case 'mission-changeurgency':
		MissionHandler::changeUrgency($_SESSION['iJobID'], $_REQUEST['iMission'], $_REQUEST['iUrgency']);
		break;
	case 'mission-changejob':
		if (!$_REQUEST['iJobID']) {
			header('Location: index.php?sView=job-view');
			exit();
		}
		$iResult = MissionHandler::changeJob($_REQUEST['iMissionID'], $_REQUEST['iJobID']);
		if ($iResult == 1) {
			header('Location: index.php?sView=job-view&iJobID='.$_REQUEST['iJobID']);
			exit();
		}
		break;
	case 'mission-changetodo':
		MissionHandler::changeMissionTodo($_REQUEST['iJobID'], $_REQUEST['iMission'], $_REQUEST['sTodo']);
		break;
	case 'mission-change':
		if ($iFinishTime == -1 || (!$_REQUEST['iHour'] && !$_REQUEST['iMonth'] && !$_REQUEST['iDay'] && !$_REQUEST['iYear']))
		{
			$iFinishTime = 0;
		}
		else {
			$iFinishTime = mktime($_REQUEST['iHour'], 0, 0, $_REQUEST['iMonth'], $_REQUEST['iDay'], $_REQUEST['iYear']);
		}
		$iResult = MissionHandler::changeMission($_SESSION['iJobID'], $_REQUEST['iMissionID'], $_REQUEST['sTodo'], $_REQUEST['iMissiongroupID'], $_REQUEST['bAssign'], $_REQUEST['iStatus'], $_REQUEST['iUrgency'], $iFinishTime, $_REQUEST['iUsers'], $_REQUEST['iFiles']);
		if ($iResult == 1)
		{
			header('Location: index.php?sView=job-view&iJobID='.$_SESSION['iJobID']);
			exit();
		}
		break;
	case 'mission-changestatus':
		MissionHandler::changeMissionStatus($_SESSION['iJobID'], $_REQUEST['iMission'], $_REQUEST['iStatus']);
		break;
	case 'mission-add':
		if (@$iFinishTime == -1 || (!@$_REQUEST['iHour'] && !@$_REQUEST['iMonth'] && !@$_REQUEST['iDay'] && !@$_REQUEST['iYear'])) {
			$iFinishTime = 0;
		}
		else {
			$iFinishTime = mktime($_REQUEST['iHour'], 0, 0, $_REQUEST['iMonth'], $_REQUEST['iDay'], $_REQUEST['iYear']);
		}
		$iResult = MissionHandler::addMission($_SESSION['iJobID'], $_REQUEST['sTodo'], $_SESSION['rid'], @$_REQUEST['iMissiongroupID'], $_REQUEST['iStatus'], $_REQUEST['iUrgency'], $iFinishTime, $_REQUEST['iUsers'], @$_REQUEST['iFiles']);
		if ($iResult > 0) {
			header('Location: index.php?sView='.$_REQUEST['sView'].'&iJobID='.$_SESSION['iJobID']);
			exit();
		}
		break;
	case 'mission-delete':
		MissionHandler::delMission($_SESSION['iJobID'], $_REQUEST['iMissionID']);
		header('Location: index.php?sView=job-view');
		exit();
		break;
	case 'mission-groupdelete':
		$iResult = JobHandler::delMissiongroup($_SESSION['iJobID'], $_REQUEST['iMissiongroupID']);
		if ($iResult == 1) {
			header('Location: index.php?sView=job-view');
			exit();
		}
		break;
	case 'mission-groupchange':
		$iResult = JobHandler::changeMissiongroup($_SESSION['iJobID'], $_REQUEST['iMissiongroupID'], $_REQUEST['sName']);
		if ($iResult == 1) {
			header('Location: index.php?sView=job-view');
			exit();
		}
		break;
	case 'mission-groupadd':
		$iResult = JobHandler::addMissiongroup($_SESSION['iJobID'], $_REQUEST['sName']);
		if ($iResult > 0) {
			header('Location: index.php?sView=job-view');
			exit();
		}
		break;
	case 'mission-rush':
		MissionHandler::rush($_SESSION['iJobID'], $_REQUEST['iMissionID'], $_REQUEST['sMessage'], $_REQUEST['iUsers'], $_REQUEST['sType']);
		break;
}
?>
